clear all
set more off
cap log close

do "H:\Lavecchia_7086\to-transfer-jan-2022\RESTAT_Replication_Programs\0_Set_Directories.do"


****************************************************************************
* This do-file extract data from the Read-only LAD files
*	- age, sex, family type and business income
* 
* Creates the following Stata files:
*	- death_min_yyyy.dta.dta
* 	- death_8299.dta (appended files)
*   - death_0016.dta (appended files)
* 
****************************************************************************

cap log using "$dir_log\1f_Extract_Death.log", replace

* Step 1: load the data from LAD read-only files

forvalues year=1989(1)2016{
use lin__i yod__i`year' using "G:\LAD\LAD_DAL_Allcycle_v3\data\data\Stata\lad`year'.dta"
sort lin__i
gen year=`year'
foreach var in yod__i {
rename `var'`year' `var'
}
save "$dir_data\Capital income years\death_`year'.dta", replace
}



* Step 2: append into one file (rename the variables to drop the year portion of the name)

**************** 1982 -- 1999 ****************
clear
use "$dir_data\Capital income years\death_1982.dta"
forvalues year=1983/1999{
append using "$dir_data\Capital income years\death_`year'.dta"
compress
}
*
save "$dir_data\death_8299.dta", replace


**************** 2000 -- 2016 ****************
clear
use "$dir_data\Capital income years\death_2000.dta"
forvalues year=2001/2016{
append using "$dir_data\Capital income years\death_`year'.dta"
compress
}
*
save "$dir_data\death_0016.dta", replace

use "$dir_data\death_8299.dta"
append using "$dir_data\death_0016.dta"
save "$dir_data\death.dta", replace
